<?php

namespace app\admin\validate\tools;

use app\admin\validate\Validates;

class Account extends Validates
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
        'ids|标识' => 'require|array',
        'id|标识' => 'require|integer|>:0',
        'price|金额' => 'float',
        'cid|分类' => 'integer|>:0',
        'datetime|账目日期' => 'require|date',
        'start_datetime|账目日期开始范围' => 'date',
        'end_datetime|账目日期结束范围' => 'date',
        'desc|描述' => 'max:100'
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [];

    /**
     * 场景验证
     * @var []
     */
    protected $scene = [
        'index' => ['cid','start_datetime','end_datetime'],
        'delete' => ['id'],
        'destory' => ['ids']
    ];

    /**
     * 定义新增场景验证
     * @return $this
     */
    public function sceneCreate()
    {
        return $this->only(['cid','datetime','price','desc'])
            ->append('cid', 'require');
    }

    /**
     * 定义编辑场景验证
     * @return $this
     */
    public function sceneUpdate()
    {
        return $this->only(['cid','datetime','price','desc'])
            ->append('cid', 'require');
    }

}
